home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
60914
/
60914.xpi
/
chrome
/
content
/
personasrotatorfileio.js
< prev
next >
Wrap
Text File
|
2010-01-20
|
2KB
|
78 lines
var PersonasRotatorFileIO = {
read:function(file,charset) {
try {
var scriptableInputStream = Components.classes['@mozilla.org/scriptableinputstream;1']
.createInstance(Components.interfaces.nsIScriptableInputStream);
var fileInputStream = Components.classes['@mozilla.org/network/file-input-stream;1']
.createInstance(Components.interfaces.nsIFileInputStream);
var data=new String();
fileInputStream.init(file,1,0,false);
scriptableInputStream.init(fileInputStream);
data+=scriptableInputStream.read(-1);
scriptableInputStream.close();
fileInputStream.close();
if (charset) {
try {
var scriptableUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
scriptableUnicodeConverter.charset = charset;
data = scriptableUnicodeConverter.ConvertToUnicode(data);
}
catch(err) {/*do nothing*/}
}
return data;
}
catch(err) {return false;}
},
write:function(file,data,mode,charset) {
try {
var fileOutputStream = Components.classes['@mozilla.org/network/file-output-stream;1']
.createInstance(Components.interfaces.nsIFileOutputStream);
if (charset) {
try {
var scriptableUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
.createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
scriptableUnicodeConverter.charset = charset;
data = scriptableUnicodeConverter.ConvertFromUnicode(data);
}
catch(err) {/*do nothing*/}
}
var flags = 0x02 | 0x08 | 0x20;
if (mode == 'a') {
flags = 0x02 | 0x10;
}
fileOutputStream.init(file, flags, 0664, 0);
fileOutputStream.write(data, data.length);
fileOutputStream.close();
return true;
}
catch(err) {return false;}
},
}